﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portfolio.IViews;
using Portfolio.Presenters;
using Portfolio.Entities;

namespace Portfolio.UI 
{
    public partial class _Default : System.Web.UI.Page, IDefaultView
    {
        private DefaultPresenter _presenter;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            _presenter = new DefaultPresenter(this);           
            //presenter.InitViewForEditing(Request.QueryString["customerID"], IsPostBack);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (LoadMenuTop != null)
                {
                    LoadMenuTop(this, EventArgs.Empty);
                    MenuTop.Items[1].Selected = true;
                    MenuTop_MenuItemClick(this, new MenuEventArgs(MenuTop.Items[1]));                    
                }
            }
        }

        protected void MenuTop_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (ClickItemMenuTop != null)
            {
                ClickItemMenuTop(this, EventArgs.Empty);
                
            } 
        }

        #region IDefaultView Members

        public event EventHandler<EventArgs> LoadMenuTop;
        public event EventHandler<EventArgs> ClickItemMenuTop;

        public IList<MenuTopView> MenuTopList
        {
            set
            {
                foreach (MenuTopView parentItem in value)
                {
                    MenuItem categoryItem = new MenuItem((string)parentItem.Name, parentItem.MenuItemID.ToString());                                        
                    MenuTop.Items.Add(categoryItem);                    
                }           
                
            }
        }

        public int IdItemMenu
        {
            get 
            {
                return Int32.Parse(MenuTop.SelectedItem.Value);
            }
        }

        public string TextArticle
        {
            set 
            {
                lblArticleText.Text = value;
            }
        }

        public string TitleArticle
        {
            set
            {
                lblArticleTitle.Text = value;
            }
        }

        public string SubTextArticle
        {
            set 
            {
                lblSubArticleText.Text = value;
            }
        }

        public string SubTitleArticle
        {
            set 
            {
                lblSubArticleTitle.Text = value; 
            }
        }

        #endregion        
    }
}
